<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission">
        <!-- <template slot="right">
          <el-button size="mini" type="info" icon="el-icon-check" class="filter-item" @click="readAll">全部读取</el-button>
        </template> -->
      </crudOperation>
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="关联">
            <el-input v-model="form.commonId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="类型">
            <el-input v-model="form.type" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="标题">
            <el-input v-model="form.title" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="客户号">
            <el-input v-model="form.uid" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="状态">
            <el-select v-model="form.status" placeholder="请选择" style="width: 370px;">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="简介">
            <el-input v-model="form.text" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="id" label="id" />
        <el-table-column prop="commonId" label="关联" />
        <el-table-column prop="type" label="类型" >
          <template slot-scope="scope">
             {{scope.row.type=='1' ? "评论消息" : scope.row.type=='2' ?'点赞消息' : scope.row.type=='3' ? '线索核实消息' : '异常'}}
          </template>
        </el-table-column>
        <el-table-column prop="title" label="标题" />
        <el-table-column prop="uid" label="客户号" />
        <el-table-column prop="status" label="状态" >
          <template slot-scope="scope">
             {{scope.row.status=='1' ? "已读" : scope.row.status=='0' ?'未读' : '异常'}}
          </template>
        </el-table-column>
        <el-table-column prop="text" label="简介" />
        <el-table-column prop="createdAt" label="创建时间" />
        <el-table-column prop="updatedAt" label="修改时间" />
        <!-- <el-table-column v-if="checkPer(['admin','dccXiaoxi:edit','dccXiaoxi:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column> -->
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudDccXiaoxi, {readAll} from '@/api/dccXiaoxi'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { id: null, commonId: null, type: null, title: null, uid: null, status: null, text: null, operator: null, createdAt: null, updatedAt: null }
export default {
  name: 'DccXiaoxi',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '消息记录', url: 'api/dccXiaoxi', idField: 'id', sort: 'id,desc', crudMethod: { ...crudDccXiaoxi }})
  },
  data() {
    return {
      options: [{
        value: 1,
        label: '已读'
      }, {
        value: 0,
        label: '未读'
      }],
      permission: {
        add: ['admin', 'dccXiaoxi:add'],
        edit: ['admin', 'dccXiaoxi:edit'],
        del: ['admin', 'dccXiaoxi:del']
      },
      rules: {
      }    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    readAll() {
      // this.crud.refresh()
      readAll().then(res=> {
        console.log(res)
      })
    }
  }
}
</script>

<style scoped>

</style>
